package com.ruoyi.web.controller.erp.scrappingcause;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.AjaxResult.Type;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erp.conventionaldata.domain.ScrappingCauseTab;
import com.ruoyi.erp.conventionaldata.service.ScrappingCauseTabBaseService;

import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "ScrappingCauseTabController")
@Controller
@RequestMapping("/scrappingCauseTabs")
@CrossOrigin
public class ScrappingCauseTabController extends BaseController {



    @Autowired
    private ScrappingCauseTabBaseService scrappingCauseTabBaseService;


    private String prefix = "erp/scrappingCauseTab";

    @RequiresPermissions("scrappingCauseTabs:scrappingCauseTab:view")
    @GetMapping("/scrappingCauseTab")
    public String list (){
        return prefix+"/list";
    }

    /***
     * 查询ScrappingCauseTab全部数据
     * @return
     */
    @RequiresPermissions("scrappingCauseTabs:scrappingCauseTab:list")
    @ApiOperation(value = "查询所有ScrappingCauseTab",notes = "查询所ScrappingCauseTab有方法详情",tags = {"ScrappingCauseTabController"})
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findAll(ScrappingCauseTab scrappingCauseTab){
        //调用ScrappingCauseTabService实现查询所有ScrappingCauseTab
        //List<ScrappingCauseTab> list = scrappingCauseTabService.findAll(scrappingCauseTab);
        List<ScrappingCauseTab> list = scrappingCauseTabBaseService.select(scrappingCauseTab);
        return  getDataTable(list);
    }



    /**
     * 新增
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }


    /***
     * 新增ScrappingCauseTab数据
     * @param scrappingCauseTab
     * @return
     */
    @RequiresPermissions("scrappingCauseTabs:scrappingCauseTab:add")
    @ApiOperation(value = "ScrappingCauseTab添加",notes = "添加ScrappingCauseTab方法详情",tags = {"ScrappingCauseTabController"})
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@ApiParam(name = "ScrappingCauseTab对象",value = "传入JSON数据",required = true) ScrappingCauseTab scrappingCauseTab){
        //调用ScrappingCauseTabService实现添加ScrappingCauseTab
        //scrappingCauseTabService.add(scrappingCauseTab);
        scrappingCauseTabBaseService.insert(scrappingCauseTab);
        return new AjaxResult(Type.SUCCESS,"添加数据成功","添加成功");
    }



    /***
     * 根据ID查询ScrappingCauseTab数据
     * @param id
     * @return
     */
    @ApiOperation(value = "ScrappingCauseTab根据ID查询",notes = "根据ID查询ScrappingCauseTab方法详情",tags = {"ScrappingCauseTabController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @GetMapping("/findScrappingCauseTab/{id}")
    public String findById(@PathVariable("id") String id,ModelMap modelMap){
        //调用ScrappingCauseTabService实现根据主键查询ScrappingCauseTab
        //ScrappingCauseTab scrappingCauseTab = scrappingCauseTabService.findById(id);
        ScrappingCauseTab scrappingCauseTab = scrappingCauseTabBaseService.selectById(id);
        modelMap.put("scrapping",scrappingCauseTab);
        return prefix+"/edit";
        //return new AjaxResult(Type.SUCCESS,"根据id查询成功",scrappingCauseTab);
    }




    /***
     * 修改ScrappingCauseTab数据
     * @param scrappingCauseTab
     *
     * @return
     */
    @RequiresPermissions("scrappingCauseTabs:scrappingCauseTab:edit")
    @ApiOperation(value = "ScrappingCauseTab根据ID修改",notes = "根据ID修改ScrappingCauseTab方法详情",tags = {"ScrappingCauseTabController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @ResponseBody
    @PostMapping("/edit")
    public AjaxResult update( @ApiParam(name = "ScrappingCauseTab对象",value = "传入JSON数据",required = false) ScrappingCauseTab scrappingCauseTab){
        //调用ScrappingCauseTabService实现修改ScrappingCauseTab
        //scrappingCauseTabService.update(scrappingCauseTab);
        scrappingCauseTabBaseService.update(scrappingCauseTab);
        return new AjaxResult(Type.SUCCESS,"根据id修改成功","修改成功");
    }


    /***
     * 根据ID删除品牌数据
     * @param ids
     * @return
     */
    @ApiOperation(value = "ScrappingCauseTab根据ID删除",notes = "根据ID删除ScrappingCauseTab方法详情",tags = {"ScrappingCauseTabController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult delete(String ids){
        //调用ScrappingCauseTabService实现根据主键删除
        //return toAjax(scrappingCauseTabService.delete(ids));

        return toAjax(scrappingCauseTabBaseService.delete(ids));

    }



//    @RequiresPermissions("goodsPath:goodpath:remove")
//    @Log(title = "删除交货路线", businessType = BusinessType.DELETE)
//    @PostMapping("/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids) {
//        return toAjax(goodPathService.deleteGoodPathByIds(ids));
//    }
//
//
//
//
    @Log(title = "导出交货路线", businessType = BusinessType.EXPORT)
    @RequiresPermissions("scrappingCauseTabs:scrappingCauseTab:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScrappingCauseTab sc)
    {
        //List<ScrappingCauseTab> scrappingCauseTab = scrappingCauseTabService.findAll(sc);
        List<ScrappingCauseTab> scrappingCauseTab = scrappingCauseTabBaseService.select(sc);
        ExcelUtil<ScrappingCauseTab> util = new ExcelUtil<ScrappingCauseTab>(ScrappingCauseTab.class);
        return util.exportExcel(scrappingCauseTab, "交货路线数据");
    }







}
